package ltd.dujiabao.springcloud.controller;

import com.netflix.discovery.converters.Auto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import ltd.dujiabao.springcloud.entities.CommonResult;
import ltd.dujiabao.springcloud.entities.Payment;
import ltd.dujiabao.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

/**
 * @author : DuJiabao
 * @Project : springcloud
 * @Time : 2021/5/21 11:26
 * @Desc :
 */
@Api("Payment")
@Slf4j
@RestController
@RequestMapping("/payment")
public class PaymentController {
  @Autowired
  PaymentService paymentService;
  @Value("${server.port}")
  private String serverPort;

  @PostMapping("/create")
  CommonResult<Object> create(@RequestBody Payment payment) {
    int res = paymentService.create(payment);
    if (res > 0) {
      log.info("插入成功，Payment：" + payment.toString() + ", Port: " + serverPort);
      return new CommonResult<>(CommonResult.SUCCESS, "插入Payment成功" + ", Port: " + serverPort);
    } else {
      log.info("插入失败，Payment：" + payment.toString() + ", Port: " + serverPort);
      return new CommonResult<>(CommonResult.FAIlURE, "插入Payment失败" + ", Port: " + serverPort);
    }
  }

  @ApiOperation("查找payment")
  @GetMapping("/get/{id}")
  CommonResult<Payment> selectById(@ApiParam(name = "id", required = true) @PathVariable("id") Long id) {
    Payment payment = paymentService.selectById(id);
    log.info("查询Payment " + id + " 为：" + payment.toString() + ", Port: " + serverPort);
    return new CommonResult<Payment>(CommonResult.SUCCESS, "查询Payment " + id + " 成功！" + ", Port: " + serverPort, payment);
  }
}
